package com.zb.util;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;

/**
 * @Author WEN
 * @Date 2024/8/30 0030
 **/
public class TestFileUtils {

    static String downloadurl = "https://hb-v4-attachment-oss.huoban.com/workflow/651223613/0?sign=q-sign-algorithm%3Dsha1%26q-ak%3DAKIDwpKza4Yu8FVfieRyqt8iP8tsrqnrvvpc%26q-sign-time%3D1724998775%3B1725002435%26q-key-time%3D1724998775%3B1725002435%26q-header-list%3Dhost%26q-url-param-list%3Dresponse-content-disposition%26q-signature%3D1c4fc00bf2ea29fe8cb060b1b50f13b677700692&response-content-disposition=attachment%3B%20filename%3D%22%25E8%2592%2599%25E7%2589%2588%25E7%25BB%2584%252052.png%22%3B%20filename%2A%3Dutf-8%27%27%25E8%2592%2599%25E7%2589%2588%25E7%25BB%2584%252052.png";


    public static void test() throws IOException {
        URL url = new URL(downloadurl);
        URLConnection con = url.openConnection();
        InputStream inputStream = con.getInputStream();
        // 构建输出流
        FileOutputStream fileOutputStream = new FileOutputStream("E:/workspace/Nginx/test.png");
        int bytesum = 0;
        int byteread;
        byte[] bytes = new byte[1024];
        while ((byteread = inputStream.read(bytes)) != -1) {
            bytesum += byteread;
            fileOutputStream.write(bytes, 0, byteread);
        }
        fileOutputStream.close();
    }


    public static void main(String[] args) throws IOException {
        test();
    }
}
